/**
 Copyright will be fixed soon.
 Author: Hiroshi Ota.
 $Date: $
 $Revision: $
*/

#include "Key.h"

#ifdef _BRICKOS_
#include "dkey.h"
#endif

Key::Key(void)
{
}

Key::~Key(void)
{
}

Key* Key::create()
{
        if (instance==0)
        {
                instance = new Key();
        }

        return instance;
}

enum Key::KEY Key::pressed(enum KEY keys)
{
        KEY key = (enum KEY)KEY_ANY;
#ifdef _BRICKOS_
        key = (enum KEY)dkey_pressed(keys);
#else
		if (simCon!=0) {
			key = (enum KEY)simCon->getKeyStatus((int)keys,true);
		}
#endif
        return key;
}

enum Key::KEY Key::released(enum KEY keys)
{
        KEY key = (enum KEY)KEY_ANY;
#ifdef _BRICKOS_
        key = (enum KEY)dkey_released(keys);
#else
		if (simCon!=0){
			key = (enum KEY)simCon->getKeyStatus((int)keys,false);
		}
#endif
        return key;
}

unsigned long Key::taskStart(wakeup fp)
{
        unsigned long result =0;
#ifdef _BRICKOS_
		// ???
#else
		if (simCon!=0) {
			result = simCon->registKeyDelegator(fp);
		}
#endif
        return result;
}

Key* Key::instance = 0;

#ifndef _BRICKOS_
Key::Key(ISimulatorControl *sc)
: simCon(sc)
{
}

Key* Key::create(ISimulatorControl *sc)
{
	if (instance !=0) {
		instance = new Key(sc);
	}
	return instance;
}

#endif
